import threading as td
import time

def job(x,y,b):
    for i in range(x,y):
        b.write(str(i) + '\n')

def job2(f,i):
    #for i in range(1,10):
    if i >=9:
        pass
    else:
        with open(str(i+2) + '.txt', 'r+') as book2:
            data = book2.read()
            f.write(data)

def start():
    th = []
    th2 = []
    for i in range(10):
        with open(str(i+1) + '.txt', 'w') as book:
            t = td.Thread(target=job, args=(1000 * i + 1, (i + 1) * 1000 + 1, book))
            t.start()
            th.append(t)
        [i.join() for i in th]
    for i in range(10):
        with open(str(1) + '.txt', 'a+') as book3:
            t = td.Thread(target=job2,args=(book3,i))
            t.start()
            th2.append(t)
            [i.join() for i in th2]

if __name__ == '__main__':
    st = time.time()
    start()
    print(time.time()-st)